//299.猜数字游戏
//https://leetcode.cn/problems/bulls-and-cows/?envType=daily-question&envId=2024-03-10
class Solution {
public:
    string getHint(string secret, string guess) {
        int x = 0, y = 0;
        string s1, s2;
        int n = secret.size();
        for (int i = 0; i < n; ++i)
        {
            if (secret[i] == guess[i]) ++x;
            else
            {
                s1 += secret[i];
                s2 += guess[i];
            }
        }
        sort(s1.begin(), s1.end());
        sort(s2.begin(), s2.end());
        n = s1.size();
        int p1 = 0;
        int p2 = 0;
        while (p1 < n && p2 < n)
        {
            if (s1[p1] == s2[p2]) ++p1, ++p2,++y;
            else if (s1[p1] < s2[p2]) ++p1;
            else ++p2;
        }
        return to_string(x) + 'A' + to_string(y) + 'B';
    }
};